package org.ims.inv.service.conference.impl;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.ims.inv.dao.conference.DAOConference;
import org.ims.inv.model.conference.ModelConference;
import org.ims.inv.service.conference.ServiceConference;

import cn.trymore.core.service.impl.ServiceGenericImpl;
import cn.trymore.core.util.UtilString;

public class ServiceConferenceImpl
extends ServiceGenericImpl<ModelConference> implements ServiceConference
{
	/**
	 * The repository of conference
	 */
	private DAOConference daoConference;
	
	/**
	 * The sole constructor
	 * 
	 * @param dao
	 */
	public ServiceConferenceImpl(DAOConference dao)
	{
		super(dao);
		this.daoConference = dao;
	}
	
	/*
	 * (non-Javadoc)
	 * @see cn.trymore.core.service.impl.ServiceGenericImpl#getCriterias(cn.trymore.core.model.ModelBase)
	 */
	@Override
	protected DetachedCriteria getCriterias(ModelConference domain)
	{
		DetachedCriteria criteria = DetachedCriteria.forClass(ModelConference.class);
		
		if (domain != null)
		{
			if (UtilString.isNotEmpty(domain.getTitle()))
			{
				criteria.add(Restrictions.like("title", domain.getTitle(), MatchMode.ANYWHERE));
			}
			
			if (UtilString.isNotEmpty(domain.getAttendeeNames()))
			{
				criteria.add(Restrictions.like("attendeeNames", domain.getAttendeeNames(), MatchMode.ANYWHERE));
			}
			
			if (domain.getStatus() != null)
			{
				criteria.add(Restrictions.eq("status", domain.getStatus()));
			}
			
			if (domain.getLeaderAudit() != null)
			{
				criteria.add(Restrictions.eq("leaderAudit", domain.getLeaderAudit()));
			}
			
		}
		
		criteria.addOrder(Order.desc("applyTime"));
		
		return criteria;
	}

	public DAOConference getDaoConference()
	{
		return daoConference;
	}

	public void setDaoConference(DAOConference daoConference)
	{
		this.daoConference = daoConference;
	}

}
